<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<?php include "../public/header_edit.php"?>
<script src="/static/admin/js/math.js"></script>
<link rel="stylesheet" type="text/css" href="/static/admin/css/main.css">
<style>
    .layui-table td, .layui-table th{text-align: center!important;padding: 0!important;height: 40px}
    #commentForm .main-container .short_table_list thead{display: table-header-group!important;}
    #commentForm .main-container .short_table_list tbody{display: table-row-group!important;}
    #commentForm .main-container .short_table_list thead > tr{display: table-row!important;}
    #commentForm .main-container .short_table_list tbody > tr{display: table-row!important;}
    .bak{background: #fafafa!important;}
    #list_list input{text-align: center}
    #heji td{font-weight: bold}
    .frght{float: right}
    #curthead tr th{font-weight: bold}
    #list_list tr td{font-size: 13px!important;}
</style>
<body class="laytp-container">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title" id="titss"></span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>
<?php include "dao.php"?>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-form layui-form-pane" id="commentForm">
                <div class="main-container" style="margin:0!important;padding: 0 10px!important;">
                    <div class="layui-form-item height_auto" style="padding: 0!important;">
                        <div class="short_table_list" key="1">
                            <div style="padding: 10px 0 5px 0;">
<!--                                <button type="button" onclick="func_geng_analy()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">更新工程量</button>-->
                                <button type="button" onclick="saveinfo()" class="layui-btn layui-btn-sm btn-dark marginr5 frght">保存</button>
                                <div class="biantit" style="color: #248bfe;font-size: 13px;float: right;margin-right: 10px"></div>
                            </div>
                            <div style="width: 100%;overflow: auto;">
                                <table class="layui-table" style="min-width: 1800px">
                                    <thead id="curthead">
                                    <tr>
                                        <th rowspan="2" style="width: 50px;">户型</th>
                                        <th rowspan="2" style="width: 80px;">建筑面积</th>
                                        <th colspan="2" style="">钢筋</th>
                                        <th colspan="2" style="">砼</th>
                                        <th colspan="2" style="">模板</th>
                                        <th colspan="2" style="">砌体</th>
                                        <th colspan="2" style="">天棚</th>
                                        <th colspan="2" style="">外墙装饰</th>
                                        <th colspan="2" style="">楼地面</th>
                                        <th colspan="2" style="">内墙抹灰</th>
                                        <th colspan="2" style="">门窗</th>
                                        <th colspan="2" style="">综合脚手架</th>
                                        <th rowspan="2" style="width: 100px;">备注</th>
                                    </tr>
                                    <tr>
                                        <th>工程量<br>（t）</th>
                                        <th>单方含量<br>（kg/m2）</th>
                                        <th>工程量<br>（m3）</th>
                                        <th>单方含量<br>（m3/m2）</th>
                                        <th>工程量<br>（m2）</th>
                                        <th>单方含量<br>（m2/m2）</th>
                                        <th>工程量<br>（m3）</th>
                                        <th>单方含量<br>（m3/m2）</th>
                                        <th>工程量<br>（m2）</th>
                                        <th>单方含量<br>（m2/m2）</th>
                                        <th>工程量<br>（m2）</th>
                                        <th>单方含量<br>（m2/m2）</th>
                                        <th>工程量<br>（m2）</th>
                                        <th>单方含量<br>（m2/m2）</th>
                                        <th>工程量<br>（m2）</th>
                                        <th>单方含量<br>（m2/m2）</th>
                                        <th>工程量<br>（m2）</th>
                                        <th>单方含量<br>（m2/m2）</th>
                                        <th>工程量<br>（m2）</th>
                                        <th>单方含量<br>（m2/m2）</th>
                                    </tr>
                                    </thead>
                                    <tbody class="short_table_tbody" id="list_list"></tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>




        </div>
    </div>
</div>


<script type="text/javascript">

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;

        facade.ajax({type: 'get', url: ask_main_analy_add,data:{enginid:param_enginid}}).done(function(res){
            if (res.code === 2000) {
                $(".biantit").html(res.data.tit);
                var data = res.data.data;
                var str = '';
                var area=steel=steel_square=concrete=concrete_square=template=template_square=masonry=masonry_square=ceiling
                    =ceiling_square=outside_wall=outside_square=ground=ground_square=inside_wall=inside_square=doors=doors_square
                    =jsj=jsj_square=explain = 0;
                for(var i=0;i<data.length;i++){
                    str += '<tr>';
                    str += '<td class="qing bak" key="'+data[i].id+'">'+data[i].qingname+'</td>';
                    str += '<td class="area bak">'+data[i].area+'</td>';
                    str += '<td><input type="number" class="layui-input steel" readonly list='+JSON.stringify(data[i].steel_list)+' value="'+data[i].steel+'" onclick="choose_xuan('+i+',\'steel\','+data[i].id+',\''+data[i].qingname+'\')"></td>';
                    str += '<td class="steel_square bak">'+data[i].steel_square+'</td>';
                    str += '<td><input type="number" class="layui-input concrete" readonly list='+JSON.stringify(data[i].concrete_list)+' value="'+data[i].concrete+'" onclick="choose_xuan('+i+',\'concrete\','+data[i].id+',\''+data[i].qingname+'\')"></td>';
                    str += '<td class="concrete_square bak">'+data[i].concrete_square+'</td>';
                    str += '<td><input type="number" class="layui-input template" readonly list='+JSON.stringify(data[i].template_list)+' value="'+data[i].template+'" onclick="choose_xuan('+i+',\'template\','+data[i].id+',\''+data[i].qingname+'\')"></td>';
                    str += '<td class="template_square bak">'+data[i].template_square+'</td>';
                    str += '<td><input type="number" class="layui-input masonry" readonly list='+JSON.stringify(data[i].masonry_list)+' value="'+data[i].masonry+'" onclick="choose_xuan('+i+',\'masonry\','+data[i].id+',\''+data[i].qingname+'\')"></td>';
                    str += '<td class="masonry_square bak">'+data[i].masonry_square+'</td>';
                    str += '<td><input type="number" class="layui-input ceiling" readonly list='+JSON.stringify(data[i].ceiling_list)+' value="'+data[i].ceiling+'" onclick="choose_xuan('+i+',\'ceiling\','+data[i].id+',\''+data[i].qingname+'\')"></td>';
                    str += '<td class="ceiling_square bak">'+data[i].ceiling_square+'</td>';
                    str += '<td><input type="number" class="layui-input outside_wall" readonly list='+JSON.stringify(data[i].outside_list)+' value="'+data[i].outside_wall+'" onclick="choose_xuan('+i+',\'outside_wall\','+data[i].id+',\''+data[i].qingname+'\')"></td>';
                    str += '<td class="outside_square bak">'+data[i].outside_square+'</td>';
                    str += '<td><input type="number" class="layui-input ground" readonly list='+JSON.stringify(data[i].ground_list)+' value="'+data[i].ground+'" onclick="choose_xuan('+i+',\'ground\','+data[i].id+',\''+data[i].qingname+'\')"></td>';
                    str += '<td class="ground_square bak">'+data[i].ground_square+'</td>';
                    str += '<td><input type="number" class="layui-input inside_wall" readonly list='+JSON.stringify(data[i].inside_list)+' value="'+data[i].inside_wall+'" onclick="choose_xuan('+i+',\'inside_wall\','+data[i].id+',\''+data[i].qingname+'\')"></td>';
                    str += '<td class="inside_square bak">'+data[i].inside_square+'</td>';
                    str += '<td><input type="number" class="layui-input doors" readonly list='+JSON.stringify(data[i].doors_list)+' value="'+data[i].doors+'" onclick="choose_xuan('+i+',\'doors\','+data[i].id+',\''+data[i].qingname+'\')"></td>';
                    str += '<td class="doors_square bak">'+data[i].doors_square+'</td>';
                    str += '<td><input type="number" class="layui-input jsj" readonly list='+JSON.stringify(data[i].jsj_list)+' value="'+data[i].jsj+'" onclick="choose_xuan('+i+',\'jsj\','+data[i].id+',\''+data[i].qingname+'\')"></td>';
                    str += '<td class="jsj_square bak">'+data[i].jsj_square+'</td>';
                    str += '<td><input type="text" class="layui-input explain" value="'+data[i].explain+'"></td>';
                    str += '</tr>';
                    area += parseFloat(data[i].area);
                    steel += parseFloat(data[i].steel);
                    steel_square += parseFloat(data[i].steel_square);
                    concrete += parseFloat(data[i].concrete);
                    concrete_square += parseFloat(data[i].concrete_square);
                    template += parseFloat(data[i].template);
                    template_square += parseFloat(data[i].template_square);
                    masonry += parseFloat(data[i].masonry);
                    masonry_square += parseFloat(data[i].masonry_square);
                    ceiling += parseFloat(data[i].ceiling);
                    ceiling_square += parseFloat(data[i].ceiling_square);
                    outside_wall += parseFloat(data[i].outside_wall);
                    outside_square += parseFloat(data[i].outside_square);
                    ground += parseFloat(data[i].ground);
                    ground_square += parseFloat(data[i].ground_square);
                    inside_wall += parseFloat(data[i].inside_wall);
                    doors += parseFloat(data[i].doors);
                    doors_square += parseFloat(data[i].doors_square);
                    jsj += parseFloat(data[i].jsj);
                    jsj_square += parseFloat(data[i].jsj_square);
                    if(i == data.length -1){
                        str += '<tr id="heji">';
                        str += '<td class="bak">合计</td>';
                        str += '<td id="he_area" class="bak">'+area.toFixed(2)+'</td>';
                        str += '<td id="he_steel" class="bak">'+steel.toFixed(3)+'</td>';
                        str += '<td id="he_steel_square" class="bak">'+steel_square.toFixed(3)+'</td>';
                        str += '<td id="he_concrete" class="bak">'+concrete.toFixed(2)+'</td>';
                        str += '<td id="he_concrete_square" class="bak">'+concrete_square.toFixed(2)+'</td>';
                        str += '<td id="he_template" class="bak">'+template.toFixed(2)+'</td>';
                        str += '<td id="he_template_square" class="bak">'+template_square.toFixed(2)+'</td>';
                        str += '<td id="he_masonry" class="bak">'+masonry.toFixed(2)+'</td>';
                        str += '<td id="he_masonry_square" class="bak">'+masonry_square.toFixed(2)+'</td>';
                        str += '<td id="he_ceiling" class="bak">'+ceiling.toFixed(2)+'</td>';
                        str += '<td id="he_ceiling_square" class="bak">'+ceiling_square.toFixed(2)+'</td>';
                        str += '<td id="he_outside_wall" class="bak">'+outside_wall.toFixed(2)+'</td>';
                        str += '<td id="he_outside_square" class="bak">'+outside_square.toFixed(2)+'</td>';
                        str += '<td id="he_ground" class="bak">'+ground.toFixed(2)+'</td>';
                        str += '<td id="he_ground_square" class="bak">'+ground_square.toFixed(2)+'</td>';
                        str += '<td id="he_inside_wall" class="bak">'+inside_wall.toFixed(2)+'</td>';
                        str += '<td id="he_inside_square" class="bak">'+inside_square.toFixed(2)+'</td>';
                        str += '<td id="he_doors" class="bak">'+doors.toFixed(2)+'</td>';
                        str += '<td id="he_doors_square" class="bak">'+doors_square.toFixed(2)+'</td>';
                        str += '<td id="he_jsj" class="bak">'+jsj.toFixed(2)+'</td>';
                        str += '<td id="he_jsj_square" class="bak">'+jsj_square.toFixed(2)+'</td>';
                        str += '<td class="bak"></td>';
                        str += '</tr>';
                    }
                }
                $('#list_list').html(str);

                jisuan_han();
                render_from();
            }
        });

    });


    function func_geng_analy() {
        

        facade.error('开发中...');
    }
    function func_cha_qing() {
        // openPage('qing.php?enginid='+param_enginid,'80%','80%');
        facade.error('开发中...');
    }
    function func_cha_basal() {
        facade.error('开发中...');
    }

    function saveinfo(){
        var list = [''];
        $('#list_list tr').each(function (i) {
            var id = $(this).find('.qing').attr('key');
            if(!id){
                return true;
            }
            var steel = $(this).find('.steel').val();
            var steel_square = $(this).find('.steel_square').text();
            var steel_list = $(this).find('.steel').attr('list');
            var concrete = $(this).find('.concrete').val();
            var concrete_square = $(this).find('.concrete_square').text();
            var concrete_list = $(this).find('.concrete').attr('list');
            var template = $(this).find('.template').val();
            var template_square = $(this).find('.template_square').text();
            var template_list = $(this).find('.template').attr('list');
            var masonry = $(this).find('.masonry').val();
            var masonry_square = $(this).find('.masonry_square').text();
            var masonry_list = $(this).find('.masonry').attr('list');
            var ceiling = $(this).find('.ceiling').val();
            var ceiling_square = $(this).find('.ceiling_square').text();
            var ceiling_list = $(this).find('.ceiling').attr('list');
            var outside_wall = $(this).find('.outside_wall').val();
            var outside_square = $(this).find('.outside_square').text();
            var outside_list = $(this).find('.outside_wall').attr('list');
            var ground = $(this).find('.ground').val();
            var ground_square = $(this).find('.ground_square').text();
            var ground_list = $(this).find('.ground').attr('list');
            var inside_wall = $(this).find('.inside_wall').val();
            var inside_square = $(this).find('.inside_square').text();
            var inside_list = $(this).find('.inside_wall').attr('list');
            var doors = $(this).find('.doors').val();
            var doors_square = $(this).find('.doors_square').text();
            var doors_list = $(this).find('.doors').attr('list');
            var jsj = $(this).find('.jsj').val();
            var jsj_square = $(this).find('.jsj_square').text();
            var jsj_list = $(this).find('.jsj').attr('list');
            var explain = $(this).find('.explain').val();
            var array = {
                id:id,
                steel:steel,
                steel_square:steel_square,
                steel_list:steel_list,
                concrete:concrete,
                concrete_square:concrete_square,
                concrete_list:concrete_list,
                template:template,
                template_square:template_square,
                template_list:template_list,
                masonry:masonry,
                masonry_square:masonry_square,
                masonry_list:masonry_list,
                ceiling:ceiling,
                ceiling_square:ceiling_square,
                ceiling_list:ceiling_list,
                outside_wall:outside_wall,
                outside_square:outside_square,
                outside_list:outside_list,
                ground:ground,
                ground_square:ground_square,
                ground_list:ground_list,
                inside_wall:inside_wall,
                inside_square:inside_square,
                inside_list:inside_list,
                doors:doors,
                doors_square:doors_square,
                doors_list:doors_list,
                jsj:jsj,
                jsj_square:jsj_square,
                jsj_list:jsj_list,
                explain:explain
            };
            list.push(array);
        });
        if(list.length == 1){facade.error('请填写明细'); return false;}



        facade.ajax({url: ask_main_analy_add, data:{enginid:param_enginid, list:list}}).done(function(res){
            if (res.code === 2000) {
                facade.success("提交成功!");
                setTimeout(() => {
                    window.location.reload();
                }, 1500);
            }
        });
    }
    function choose_xuan(index, type, qingid, qingname){
        openPage('analy_xuan.php?qingid='+qingid+'&index='+index+'&type='+type+'&enginid='+param_enginid, '80%','80%');
    }






    function jisuan_han() {
        var he_steel = he_concrete = he_template = he_masonry = he_ceiling = he_outside_wall = he_ground = he_inside_wall = he_doors = he_jsj =
            he_steel_square = he_concrete_square = he_template_square = he_masonry_square = he_ceiling_square = he_outside_square =
                he_ground_square = he_inside_square = he_doors_square = he_jsj_square = 0;
        $('#list_list tr').each(function () {
            var area = $(this).find('.area').text() || 0;
            var steel = $(this).find('.steel').val() || 0;
            var concrete = $(this).find('.concrete').val() || 0;
            var template = $(this).find('.template').val() || 0;
            var masonry = $(this).find('.masonry').val() || 0;
            var ceiling = $(this).find('.ceiling').val() || 0;
            var outside_wall = $(this).find('.outside_wall').val() || 0;
            var ground = $(this).find('.ground').val() || 0;
            var inside_wall = $(this).find('.inside_wall').val() || 0;
            var doors = $(this).find('.doors').val() || 0;
            var jsj = $(this).find('.jsj').val() || 0;
            he_steel += parseFloat(steel);
            he_concrete += parseFloat(concrete);
            he_template += parseFloat(template);
            he_masonry += parseFloat(masonry);
            he_ceiling += parseFloat(ceiling);
            he_outside_wall += parseFloat(outside_wall);
            he_ground += parseFloat(ground);
            he_inside_wall += parseFloat(inside_wall);
            he_doors += parseFloat(doors);
            he_jsj += parseFloat(jsj);
            if(area != '' && area != 0){
                var steel_square = parseFloat(steel) / parseFloat(area) * 1000;
                var concrete_square = parseFloat(concrete) / parseFloat(area);
                var template_square = parseFloat(template) / parseFloat(area);
                var masonry_square = parseFloat(masonry) / parseFloat(area);
                var ceiling_square = parseFloat(ceiling) / parseFloat(area);
                var outside_square = parseFloat(outside_wall) / parseFloat(area);
                var ground_square = parseFloat(ground) / parseFloat(area);
                var inside_square = parseFloat(inside_wall) / parseFloat(area);
                var doors_square = parseFloat(doors) / parseFloat(area);
                var jsj_square = parseFloat(jsj) / parseFloat(area);
                $(this).find('.steel_square').text(steel_square.toFixed(3));
                $(this).find('.concrete_square').text(concrete_square.toFixed(2));
                $(this).find('.template_square').text(template_square.toFixed(2));
                $(this).find('.masonry_square').text(masonry_square.toFixed(2));
                $(this).find('.ceiling_square').text(ceiling_square.toFixed(2));
                $(this).find('.outside_square').text(outside_square.toFixed(2));
                $(this).find('.ground_square').text(ground_square.toFixed(2));
                $(this).find('.inside_square').text(inside_square.toFixed(2));
                $(this).find('.doors_square').text(doors_square.toFixed(2));
                $(this).find('.jsj_square').text(jsj_square.toFixed(2));
            }
        });

        var he_area = $('#he_area').text();
        if(he_area != ''){
            he_steel_square = he_steel / parseFloat(he_area) * 1000;
            he_concrete_square = he_concrete / parseFloat(he_area);
            he_template_square = he_template / parseFloat(he_area);
            he_masonry_square = he_masonry / parseFloat(he_area);
            he_ceiling_square = he_ceiling / parseFloat(he_area);
            he_outside_square = he_outside_wall / parseFloat(he_area);
            he_ground_square = he_ground / parseFloat(he_area);
            he_inside_square = he_inside_wall / parseFloat(he_area);
            he_doors_square = he_doors / parseFloat(he_area);
            he_jsj_square = he_jsj / parseFloat(he_area);

            if(isNaN(he_steel_square) || he_steel_square == 'Infinity'){he_steel_square = 0;}
            if(isNaN(he_concrete_square) || he_concrete_square == 'Infinity'){he_concrete_square = 0;}
            if(isNaN(he_template_square) || he_template_square == 'Infinity'){he_template_square = 0;}
            if(isNaN(he_masonry_square) || he_masonry_square == 'Infinity'){he_masonry_square = 0;}
            if(isNaN(he_ceiling_square) || he_ceiling_square == 'Infinity'){he_ceiling_square = 0;}
            if(isNaN(he_outside_square) || he_outside_square == 'Infinity'){he_outside_square = 0;}
            if(isNaN(he_ground_square) || he_ground_square == 'Infinity'){he_ground_square = 0;}
            if(isNaN(he_inside_square) || he_inside_square == 'Infinity'){he_inside_square = 0;}
            if(isNaN(he_doors_square) || he_doors_square == 'Infinity'){he_doors_square = 0;}
            if(isNaN(he_jsj_square) || he_jsj_square == 'Infinity'){he_jsj_square = 0;}
        }

        $('#he_steel').text(he_steel.toFixed(3));
        $('#he_concrete').text(he_concrete.toFixed(2));
        $('#he_template').text(he_template.toFixed(2));
        $('#he_masonry').text(he_masonry.toFixed(2));
        $('#he_ceiling').text(he_ceiling.toFixed(2));
        $('#he_outside_wall').text(he_outside_wall.toFixed(2));
        $('#he_ground').text(he_ground.toFixed(2));
        $('#he_inside_wall').text(he_inside_wall.toFixed(2));
        $('#he_doors').text(he_doors.toFixed(2));
        $('#he_jsj').text(he_jsj.toFixed(2));


        $('#he_steel_square').text(he_steel_square.toFixed(3));
        $('#he_concrete_square').text(he_concrete_square.toFixed(2));
        $('#he_template_square').text(he_template_square.toFixed(2));
        $('#he_masonry_square').text(he_masonry_square.toFixed(2));
        $('#he_ceiling_square').text(he_ceiling_square.toFixed(2));
        $('#he_outside_square').text(he_outside_square.toFixed(2));
        $('#he_ground_square').text(he_ground_square.toFixed(2));
        $('#he_inside_square').text(he_inside_square.toFixed(2));
        $('#he_doors_square').text(he_doors_square.toFixed(2));
        $('#he_jsj_square').text(he_jsj_square.toFixed(2));
    }
</script>
</body>
</html>
